package leetCode;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * 实现 pow(x, n) ，即计算 x 的整数 n 次幂函数（即，xn
 *
 * @author 司松坡
 * @createTime 2023年03月21日
 */
public class LeetCode50 {
    public double myPow(double x, int n) {
        if (x == 0.0f) return 0.0d;
        long b = n;
        double res = 1.0;
        if (b < 0) {
            x = 1 / x;
            b = -b;
        }
        while (b > 0) {
            if ((b & 1) == 1) {
                res *= x;
            }
            x *= x;
            b >>= 1;
        }
        return res;
    }

    @Test
    public void test() {
        System.out.println(myPow(2, -2));
    }


    @Test
    public void test111() {
        List<String> stringList = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            stringList.add("test" + i);
        }
        List<String> stringList1 = new ArrayList<>();
        for (int length = 0; length < stringList.size(); length += 5) {
            if (length + 5 < stringList.size()) {
                stringList1 = stringList.subList(length, length + 5);
            } else {
                stringList1 = stringList.subList(length, stringList.size());
            }
            System.out.println(stringList1.toString());
        }
        System.out.println("jeishu");


    }
}
